<?php  
include_once('../bootstrap.php');
$marker = Doctrine::getTable('marker')->find($_POST['id']);
$results = array('logos'=>array());
$results["nombre"] = utf8_encode($marker->nombre);
$results["nombreUrl"] = $marker->nombreUrl;
$results["direccion"] = utf8_encode($marker->calle.' '.$marker->numero);  
$results["horario"] = utf8_encode($marker->horario);
$results["telefono"] = utf8_encode($marker->telefono);
$results["email"] = utf8_encode(makeMail($marker->email));
$results["web"] = utf8_encode(makeLink($marker->web));
$results["categoriasToIds"] = implode(',', Categoria::toIds($marker->categorias));
$results["quienes"] = utf8_encode($marker->quienes);
$results["que"] = utf8_encode($marker->que);
$results["porque"] = utf8_encode($marker->porque);
$results["comentario"] = utf8_encode($marker->comentario);
foreach ($marker->campanas as $camapana) {
    $results['logos'][] = $camapana->logo;
}
$results = json_encode($results);
header("Content-type: application/json");
echo($results);

function makeLink($text) {
    $text = preg_replace('@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.#!]*(\?\S+)?)?)*)@', '<a href="$1" target="blank">$1</a>', $text);
    return str_replace("href=\"www.","href=\"http://www.",$text);
}

function makeMail ($string) {
    return preg_replace("/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i","<a href=\"mailto:$1\">$1</a>",$string);

}
?>